package com.f5.management.dao;

import com.f5.management.entity.Building;
import com.f5.management.entity.Community;
import com.f5.management.entity.RealEstate;
import com.f5.management.entity.dto.RealEstateUserDto;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface RealEstateDAO {

    //分页查询
    List<RealEstateUserDto> findAll();

    //通过编号查询
    List<RealEstateUserDto> findByNumber(String serialNumber,int rid);

    //删除信息
    @Delete("delete from real_estate_management where id = #{id}")
    int delInfo(int id);

    //添加
    @Insert("insert into real_estate_management(id,cid,bid,serialNumber,name," +
            "rooms,unit,floor,represent,createTime) values(default,#{cid},#{bid},#{serialNumber}," +
            "#{name},#{rooms},#{unit},#{floor},#{represent},#{createTime})")
    int add(RealEstateUserDto realEstateUserDto);

    //查询存在的房产及编号
    @Select("select count(id) from real_estate_management")
    int count();

    //查询最新添加数据的id
    @Select("SELECT id from real_estate_management order by id DESC LIMIT 1")
    int selectId();

    //id查询数据进行修改
    RealEstateUserDto findById(int id);

    //修改
    @Update("update real_estate_management re set re.serialNumber=#{serialNumber}" +
            ",re.name=#{name},re.represent=#{represent} where re.id = #{id}")
    int updateInfo(RealEstateUserDto realEstateUserDto);

    //查询编号是否存在
    @Select("select serialNumber from real_estate_management where serialNumber = #{serialNumber}")
    String selectNumber(String serialNumber);
}
